<script>
import setup from './setup'

export default {
  name: "form",
  setup
}
</script>

<template>
  <el-form
    ref="<%=ref%>"
    :model="<%=model.name%>"
    <%-$parseAttrs(attrs)%>
  >
  <%_ Object.entries(model.items).forEach(function(item){ _%>
    <el-form-item label="<%=item[1].label%>" prop="<%=item[0]%>"
      <%if(item[1].rules){_%> :rules="[<%-$formatRules(item[1].rules)%>]" <%}%>
    >
    <%# input-text -%>
    <%if(item[1].widget.name === 'input:text'){%>
    <el-input v-model="<%=model.name%>.<%=item[0]%>"
      <%-$parseAttrs(item[1].widget.attrs)%>
    ></el-input>
    <%}%>
    <%# select -%>
    <%if(item[1].widget.name === 'select'){%>
    <el-select v-model="<%=model.name%>.<%=item[0]%>"
      <%-$parseAttrs(item[1].widget.attrs)%>
    >
      <el-option
        <%-$parseAttrs(item[1].widget.option.attrs)%>
        v-for="<%=item[1].widget.option.for%>"
        :key="<%=item[1].widget.option.key%>"
      ></el-option>
    </el-select>
    <%}%>
    <%# textarea -%>
    <%if(item[1].widget.name === 'textarea'){%>
      <el-input v-model="<%=model.name%>.<%=item[0]%>"
        type="textarea"
        <%-$parseAttrs(item[1].widget.attrs)%>
      ></el-input>
    <%}%>
    <%# radio -%>
    <%if(item[1].widget.name === 'radio'){%>
      <el-radio-group v-model="<%=model.name%>.<%=item[0]%>"
        <%-$parseAttrs(item[1].widget.attrs)%>  
      >
        <el-radio
          <%-$parseAttrs(item[1].widget.option.attrs)%>
          v-for="<%=item[1].widget.option.for%>"
          :key="<%=item[1].widget.option.key%>"
        >
        </el-radio>
      </el-radio-group>
    <%}%>
    <%# checkbox list -%>
    <%if(item[1].widget.name === 'checkbox:list'){%>
      <el-checkbox-group v-model="<%=model.name%>.<%=item[0]%>"
        <%-$parseAttrs(item[1].widget.attrs)%>  
      >
        <el-checkbox
          <%-$parseAttrs(item[1].widget.option.attrs)%>
          v-for="<%=item[1].widget.option.for%>"
          :key="<%=item[1].widget.option.key%>"
        >
        </el-checkbox>
      </el-checkbox-group>
    <%}%>
    <%# checkbox single -%>
    <%if(item[1].widget.name === 'checkbox'){%>
      <el-checkbox
        v-model="<%=model.name%>.<%=item[0]%>"
        <%-$parseAttrs(item[1].widget.attrs)%>
      >
      </el-checkbox>
    <%}%>
    <%# datepicker -%>
    <%if(item[1].widget.name === 'datepicker'){%>
      <el-date-picker
        v-model="<%=model.name%>.<%=item[0]%>"
        <%-$parseAttrs(item[1].widget.attrs)%>
      >
      </el-date-picker>
    <%}%>
    </el-form-item>
  <% }); %>
  </el-form>
</template>
